home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 April / PCWorld_2008-04_cd.bin / v cisle / ozo / zotero-1.0.3.xpi / chrome / zotero.jar / content / zotero / note.js < prev    next >
Encoding:
JavaScript  |  2007-12-15  |  3.0 KB  |  101 lines

  1. /*
  2.     ***** BEGIN LICENSE BLOCK *****
  3.     
  4.     Copyright (c) 2006  Center for History and New Media
  5.                         George Mason University, Fairfax, Virginia, USA
  6.                         http://chnm.gmu.edu
  7.     
  8.     Licensed under the Educational Community License, Version 1.0 (the "License");
  9.     you may not use this file except in compliance with the License.
  10.     You may obtain a copy of the License at
  11.     
  12.     http://www.opensource.org/licenses/ecl1.php
  13.     
  14.     Unless required by applicable law or agreed to in writing, software
  15.     distributed under the License is distributed on an "AS IS" BASIS,
  16.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.     See the License for the specific language governing permissions and
  18.     limitations under the License.
  19.     
  20.     ***** END LICENSE BLOCK *****
  21. */
  22.  
  23. var noteEditor;
  24. var notifierUnregisterID;
  25.  
  26. function onLoad()
  27. {
  28.     noteEditor = document.getElementById('note-editor');
  29.     noteEditor.focus();
  30.     
  31.     // Set font size from pref
  32.     Zotero.setFontSize(noteEditor);
  33.     
  34.     var params = new Array();
  35.     var b = document.location.href.substr(document.location.href.indexOf('?')+1).split('&');
  36.     for(var i = 0; i < b.length; i++)
  37.     {
  38.         var mid = b[i].indexOf('=');
  39.         
  40.         params[b[i].substr(0,mid)] = b[i].substr(mid+1);
  41.     }
  42.     var itemID = params['id'];
  43.     var collectionID = params['coll'];
  44.     var parentItemID = params['p'];
  45.     
  46.     if (itemID) {
  47.         var ref = Zotero.Items.get(itemID);
  48.         
  49.         // Make sure Undo doesn't wipe out the note
  50.         if (!noteEditor.note || noteEditor.note.getID() != ref.getID()) {
  51.             noteEditor.id('noteField').editor.enableUndo(false);
  52.         }
  53.         noteEditor.note = ref;
  54.         noteEditor.id('noteField').editor.enableUndo(true);
  55.         
  56.         document.title = ref.getNoteTitle();
  57.     }
  58.     else if (parentItemID) {
  59.         var ref = Zotero.Items.get(parentItemID);
  60.         noteEditor.item = ref;
  61.     }
  62.     else
  63.     {
  64.         if(collectionID && collectionID != '' && collectionID != 'undefined')
  65.             noteEditor.collection = Zotero.Collections.get(collectionID);
  66.     }
  67.     
  68.     notifierUnregisterID = Zotero.Notifier.registerObserver(NotifyCallback, 'item');
  69. }
  70.  
  71. function onUnload()
  72. {
  73.     if(noteEditor && noteEditor.value)
  74.         noteEditor.save();
  75.     
  76.     Zotero.Notifier.unregisterObserver(notifierUnregisterID);
  77. }
  78.  
  79. var NotifyCallback = {
  80.     notify: function(action, type, ids){
  81.         // DEBUG: why does this reset without checking the modified ids?
  82.         if (noteEditor.note) {
  83.             noteEditor.note = noteEditor.note;
  84.             
  85.             // If the document title hasn't yet been set, reset undo so
  86.             // undoing to empty isn't possible
  87.             var noteTitle = noteEditor.note.getNoteTitle();
  88.             if (!document.title && noteTitle != '') {
  89.                 noteEditor.id('noteField').editor.enableUndo(false);
  90.                 noteEditor.id('noteField').editor.enableUndo(true);
  91.                 document.title = noteTitle;
  92.             }
  93.             
  94.             // Update the window name (used for focusing) in case this is a new note
  95.             window.name = 'zotero-note-' + noteEditor.note.getID();
  96.         }
  97.     }
  98. }
  99.  
  100. addEventListener("load", function(e) { onLoad(e); }, false);
  101. addEventListener("unload", function(e) { onUnload(e); }, false);